import React, { useState, useEffect } from 'react'
import { View, Image, Text, } from '@tarojs/components'
import Taro, { useDidShow,useShareAppMessage,useShareTimeline } from '@tarojs/taro'
import { AtTabs } from 'taro-ui'
import ToLogin from '../../compontents/toLogin'
import './index.less'

//  组件引入 
import Concat from './concat'
import TopInfo from './topInfo'
import Ticket from './ticket'
import Intro from './intro'
import Foot from './footer'


import api from '../../http/api'
const { ajaxBusinessDetail } = api

export default (props: any) => {
  const uBusinessId = parseInt(props.tid.split('uBusinessId=')[1].split('&')[0])
  const topInfoData = {
    imgList: [IMGSRC + 'uBanner.png', IMGSRC + 'uBanner.png']
  }
  const concatData = {
    businessTime: '时间', tel: '电话', address: '地址'
  }
  const introData = {
    info: '<div>购买须知</div>',
    goods: '<div>商品详情</div>'
  }
  const [data, setData] = useState({"id":20,"manageId":11,"uSchoolId":1,"businessManageId":34,"userName":"test0990","title":"三不牛腩","src":"https://static.zhongningwenhua.com/uniSchool/upload/f0f08461f185c02bb61ac07789a7437d.png","time":"2021-12-13T07:40:43.000Z","uType":1,"tel":"13321280684","name":"","address":"咸安区银泉大道84号","endTime":"2021-04-30T07:39:30.000Z","businessTime":"早上09:30-晚上09:30","buyNotice":"<p><img src=\"https://static.zhongningwenhua.com/uniSchool/upload/3b6bac853025f1fa0c0a1f82caf48c59.png\" style=\"max-width:100%;\"><br></p>","detail":"<p><img src=\"https://static.zhongningwenhua.com/uniSchool/upload/9b9995080e9f490ea1256e5f1e7a319d.png\" style=\"max-width:100%;\"><br></p>","isGrounding":1,"ord":0,"topNum":2,"longitude":"","latitude":"","price":"158","priceOld":"300","num":0,"numTotal":200,"topIco":"https://static.zhongningwenhua.com/uniSchool/img/uShopIco.png","ticket":[{"id":34,"uSchoolId":1,"uBusinessId":20,"content":"2-4人餐","price":"158","priceOld":"300","num":0,"numTotal":200,"src":"https://static.zhongningwenhua.com/uniSchool/upload/fc7dd0c01e3b42c62db5ab41856443ea.png"}],"numOld":4})
  const getData = () => {
    ajaxBusinessDetail({ uBusinessId }).then((res: any) => {
      setData(res.data)
    })
  }
  useEffect(() => {
    api.version().then((res:any)=>{
      const version = res.data
      if(version ===1){
        getData()
      }
    })
  },[])
  useShareAppMessage(res => {
    if (res.from === 'button') {
      // 来自页面内转发按钮
      console.log(res.target)
    }
    return {
      title: `u选商家 ${data.title}`,
      path: `/pages/uBusinessDetail/index?uBusinessId=${uBusinessId}`
    }
  })
  useShareTimeline(()=>{
    return {
      title: `u选商家 ${data.title}`,
      path: `/pages/uBusinessDetail/index?uBusinessId=${uBusinessId}`
    }
  })
  return (
    <View className='uBusinessDetail'>
      <ToLogin url={`/pages/uBusinessDetail/index?uBusinessId=${uBusinessId}`}></ToLogin>
      {
         <View>
          <TopInfo data={data} />
          <Ticket data={data}/>
          <Concat data={data} />
          <Intro data={data} />
          <Foot uBusinessId='uBusinessId' data={data} />
        </View>
      }
    </View>
  );
};
